package orgd

import (
	"time"

	corgd "gogs.xiaoyuanjijiehao.com/antlinker/antcms/core/orgd"

	"gogs.xiaoyuanjijiehao.com/antlinker/antcms/core/common"
	"gogs.xiaoyuanjijiehao.com/antlinker/antcms/ddd"
)

// @collname 组织集合(i_org)
type collOrg struct {
	OrgID      string    `bson:"_id" `
	Icon       []string  `bson:"icon"`       //展示图片
	Columnids  []string  `bson:"columnids"`  //显示的栏目
	Status     int       `bson:"status"`     //状态 -1 删除 0 正常
	Creator    string    `bson:"creator"`    //创建人
	CreTime    time.Time `bson:"creTime"`    //创建时间
	UpdateTime time.Time `bson:"updateTime"` //最后更新时间
	Updater    string    `bson:"updater"`    //最后更新人
	DeleteTime time.Time `bson:"deleteTime"` //删除时间
	Deleter    string    `bson:"deleter"`    //删除人

}

func (c collOrg) IsCache() bool {
	return c.OrgID != "" && c.Status == 0
}
func (c collOrg) CacheExpire() time.Duration {
	return 600 * time.Second
}
func (c collOrg) CollID() string {
	return c.OrgID
}
func (collOrg) CollName() string {
	return collNameOrg
}

func (c *collOrg) FullDesc(e corgd.OrgDesc) {
	c.Icon = e.Icon
	c.Columnids = e.Columnids
	c.Status = e.Status

}
func (c collOrg) ToDesc() corgd.OrgDesc {
	return corgd.OrgDesc{
		Icon:      c.Icon,
		Columnids: c.Columnids,
		Status:    c.Status,
	}
}

func (c *collOrg) FullOperator(e common.Operator) {
	c.Creator = e.Creator
	c.CreTime = e.CreTime
	c.UpdateTime = e.UpdateTime
	c.Updater = e.Updater
	c.DeleteTime = e.DeleteTime
	c.Deleter = e.Deleter

}
func (c collOrg) ToOperator() common.Operator {
	return common.Operator{
		Creator:    c.Creator,
		CreTime:    c.CreTime,
		UpdateTime: c.UpdateTime,
		Updater:    c.Updater,
		DeleteTime: c.DeleteTime,
		Deleter:    c.Deleter,
	}
}

func (c collOrg) ToAggregate() ddd.Aggregate {
	return c.ToOrgAggregate()
}
func (c collOrg) ToOrgAggregate() *corgd.OrgAggregate {
	return &corgd.OrgAggregate{
		OrgID:   c.OrgID,
		OrgDesc: c.ToDesc(),

		Operator: c.ToOperator(),
	}
}
